#include <stdio.h>
#include <string.h>
#include "rpmpgp.h"

static unsigned char sha_mbles_1_bin[] = {
	0x99, 0x04, 0x0d, 0x04, 0x7f, 0xe8, 0x17, 0x80, 0x01, 0x20, 0x00, 0xff,
	0x4b, 0x65, 0x79, 0x20, 0x69, 0x73, 0x20, 0x70, 0x61, 0x72, 0x74, 0x20,
	0x6f, 0x66, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6c, 0x6c, 0x69, 0x73, 0x69,
	0x6f, 0x6e, 0x21, 0x20, 0x49, 0x74, 0x27, 0x73, 0x20, 0x61, 0x20, 0x74,
	0x72, 0x61, 0x70, 0x21, 0x79, 0xc6, 0x1a, 0xf0, 0xaf, 0xcc, 0x05, 0x45,
	0x15, 0xd9, 0x27, 0x4e, 0x73, 0x07, 0x62, 0x4b, 0x1d, 0xc7, 0xfb, 0x23,
	0x98, 0x8b, 0xb8, 0xde, 0x8b, 0x57, 0x5d, 0xba, 0x7b, 0x9e, 0xab, 0x31,
	0xc1, 0x67, 0x4b, 0x6d, 0x97, 0x43, 0x78, 0xa8, 0x27, 0x73, 0x2f, 0xf5,
	0x85, 0x1c, 0x76, 0xa2, 0xe6, 0x07, 0x72, 0xb5, 0xa4, 0x7c, 0xe1, 0xea,
	0xc4, 0x0b, 0xb9, 0x93, 0xc1, 0x2d, 0x8c, 0x70, 0xe2, 0x4a, 0x4f, 0x8d,
	0x5f, 0xcd, 0xed, 0xc1, 0xb3, 0x2c, 0x9c, 0xf1, 0x9e, 0x31, 0xaf, 0x24,
	0x29, 0x75, 0x9d, 0x42, 0xe4, 0xdf, 0xdb, 0x31, 0x71, 0x9f, 0x58, 0x76,
	0x23, 0xee, 0x55, 0x29, 0x39, 0xb6, 0xdc, 0xdc, 0x45, 0x9f, 0xca, 0x53,
	0x55, 0x3b, 0x70, 0xf8, 0x7e, 0xde, 0x30, 0xa2, 0x47, 0xea, 0x3a, 0xf6,
	0xc7, 0x59, 0xa2, 0xf2, 0x0b, 0x32, 0x0d, 0x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0, 0xba,
	0xb2, 0x41, 0x3d, 0x4d, 0xe0, 0x0e, 0xe7, 0x1e, 0xe0, 0x1f, 0x16, 0x2b,
	0xdb, 0x6d, 0x1e, 0xaf, 0xd9, 0x25, 0xe6, 0xae, 0xba, 0xae, 0x6a, 0x35,
	0x4e, 0xf1, 0x7c, 0xf2, 0x05, 0xa4, 0x04, 0xfb, 0xdb, 0x12, 0xfc, 0x45,
	0x4d, 0x41, 0xfd, 0xd9, 0x5c, 0xf2, 0x45, 0x96, 0x64, 0xa2, 0xad, 0x03,
	0x2d, 0x1d, 0xa6, 0x0a, 0x73, 0x26, 0x40, 0x75, 0xd7, 0xf1, 0xe0, 0xd6,
	0xc1, 0x40, 0x3a, 0xe7, 0xa0, 0xd8, 0x61, 0xdf, 0x3f, 0xe5, 0x70, 0x71,
	0x88, 0xdd, 0x5e, 0x07, 0xd1, 0x58, 0x9b, 0x9f, 0x8b, 0x66, 0x30, 0x55,
	0x3f, 0x8f, 0xc3, 0x52, 0xb3, 0xe0, 0xc2, 0x7d, 0xa8, 0x0b, 0xdd, 0xba,
	0x4c, 0x64, 0x02, 0x0d
};

int main(void)
{
	char *safehash = "4f3d9be4a472c4dae83c6314aa6c36a064c1fd14";
	/* SHA-1 output:  8ac60ba76f1999a1ab70223f225aefdc78d4ddc0 */
	char *output = NULL;
	DIGEST_CTX ctx;

	rpmInitCrypto();
	if ((ctx = rpmDigestInit(PGPHASHALGO_SHA1, 0)) &&
	    !rpmDigestUpdate(ctx, sha_mbles_1_bin, sizeof(sha_mbles_1_bin)) &&
	    !rpmDigestFinal(ctx, (void **)&output, NULL, 1) &&
	    !strcmp(output, safehash)) {
		printf("OK\n");
		return 0;
	} else {
		printf("FAILURE\nGot %s\nExpected %s\n", output, safehash);
		return 1;
	}
}
